package com.lxy.demo.controller;

import com.github.pagehelper.PageInfo;
import com.lxy.demo.service.InvitationService;
import com.lxy.demo.service.ReplyDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Component
@RequestMapping("/invitation")
public class InvitationController {

    @Autowired
    private InvitationService invitationService;

    @Autowired
    private ReplyDetailService replyDetailService;

    @RequestMapping("/main")
    public String main(@RequestParam(required = false) String searchTitle,
                     @RequestParam(required = false,defaultValue = "1") Integer pageNum,
                     Model model){
        //取

        //调
        PageInfo pageInfo = invitationService.getInvitationListByPB(searchTitle, pageNum);
        //存
        model.addAttribute("pageInfo",pageInfo);
        model.addAttribute("searchTitle",searchTitle);
        //转
        return "main";
    }

    @RequestMapping("/del/{id}")
    public String del(@PathVariable("id") Integer invid, Model model){
        boolean b = replyDetailService.delInv(invid);
        if (b){
            model.addAttribute("del","ok");
        }else {
            model.addAttribute("del","no");
        }
        return "forward:/invitation/main";
    }
}
